<?php
class Notice extends AppModel {
	public  $name = 'Notice';
	public  $belongsTo = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	public  $hasMany = array(
		'Favor' => array(
			'className' => 'Favor',
			'foreignKey' => 'notice_id',
			'dependent' => false
		)
	);

        public function addNotice($data){
            $this->create();
            if ($this->save($data)){
                return true;
            }else{
                return false;
            }
        }
        public function latestNotice($userId){
            $notice = $this->find('first',array('conditions' => array('Notice.user_id' => $userId), 'recursive' => -1, 'order' => 'Notice.id DESC'));
            if($notice){
                return $notice;
            }else{
                return false;
            }
        }
}
?>